local zhongyi = fk.CreateSkill{
    name = "XD__zhongyi",
    dynamic_desc = function (self, player, lang)
        local str = "出牌阶段开始时，你可以弃置一张装备牌或废除一个装备栏，视为你使用一张目标唯一的"
        if not player:hasSkill("XD__sheyu") then
            str = str .. "普通锦囊牌或基本牌。"
        else
            str = str .. "普通锦囊牌；当你失去“奢欲”时，将“普通锦囊牌”改为“普通锦囊牌或基本牌”。"
        end
        return str
    end,
}
Fk:loadTranslationTable{
    ["XD__zhongyi"] = "终意",
    [":XD__zhongyi"] = "出牌阶段开始时，你可以弃置一张装备牌或废除一个装备栏，视为你使用一张目标唯一的普通锦囊牌；当你失去“奢欲”时，将“普通锦囊牌”改为“普通锦囊牌或基本牌”。",
    ["#XD__zhongyi-use"] = "终意：弃置一张装备牌或废除一个装备栏以视为使用一张 <font color='#0598BC'>%arg</font>",
    ["#XD__zhongyi"] = "终意：你可以弃置一张装备牌或废除一个装备栏，视为使用一张目标唯一的%arg",
    ["XD__zhongyi_active"] = "终意",
    ["XD__zhongyi_discard"] = "弃置一张装备牌",
}

zhongyi:addEffect(fk.EventPhaseStart, {
    can_trigger = function (self, event, target, player, data)
        return player == target and player.phase == Player.Play and player:hasSkill(zhongyi.name)
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local names = {}
        local str = "普通锦囊牌"
        if not player:hasSkill("XD__sheyu") then str = "基本牌或普通锦囊牌" end
        for _, name in ipairs(Fk:getAllCardNames("bt")) do
            local card = Fk:cloneCard(name)
            if (card.type == Card.TypeTrick or not player:hasSkill("XD__sheyu")) and not card.multiple_targets then
                table.insert(names, name)
            end
        end
        local use = player.room:askToUseVirtualCard(player, {
            name = names,
            skill_name = zhongyi.name,
            skip = true,
            cancelable = true,
            prompt = "#XD__zhongyi:::"..str
        })
        if use then
            local bool, dat = room:askToUseActiveSkill(player, {
                skill_name = "XD__zhongyi_active",
                prompt = "#XD__zhongyi-use:::"..use.card.name,
            })
            if bool and dat then
                event:setCostData(self, {use = use, cards = dat.cards, choice = dat.interaction})
                return true
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local dat = event:getCostData(self)
        if dat.choice == "XD__zhongyi_discard" then
            room:throwCard(dat.cards, zhongyi.name, player)
        else
            room:abortPlayerArea(player, dat.choice)
        end
        room:useCard(dat.use)
    end,
})

return zhongyi